package vip.youngboy.freejump.domain.bus;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class BusData {

    /**
     * 表关系
     */
    private BusTableRel busTableRel;

    /**
     * 主数据
     */
    private Map<String, Object> data = Maps.newHashMap();

    /**
     * 子数据
     */
    private Map<String, List<BusData>> children = Maps.newHashMap();

    /**
     * 父类
     */
    private BusData parent;

    /**
     * 添加子对象
     *
     * @param busData 业务对象
     */
    public void addChildren(BusData busData) {
        String tableKey = busData.getBusTableRel().getBusTable().getKey();
        //判断当前子类是否存在系统的tableKey
        List<BusData> childrens = this.children.computeIfAbsent(tableKey, (v) -> Lists.newArrayList());
        busData.setParent(this);
        childrens.add(busData);
    }


}
